package registnet.base;

/**
 * An implementation of a student's classification. The student's classification is 
 * determined on the basis of units completed. A student can be cassified as Freshman,
 * Sophomore, etc.
 */
public class Classification {

	/**
	 * The string description of the classification.
	 */
	private String classification;
	
	/**
	 * <i>FRESHMAN</i> Classification
	 */
	public static final Classification FRESHMAN=new Classification("FRESHMAN"); 
	
	/**
	 * <i>SOPHOMORE</i> Classification
	 */
	public static final Classification SOPHOMORE=new Classification("SOPHOMORE");
	
	/**
	 * <i>JUNIOR</i> Classification
	 */
	public static final Classification JUNIOR=new Classification("JUNIOR");
	
	/**
	 * <i>SENIOR</i> Classification
	 */
	public static final Classification SENIOR=new Classification("SENIOR");
	
	/**
	 * <i>SUPER_SENIOR</i> Classification
	 */
	public static final Classification SUPER_SENIOR=new Classification("SUPER_SENIOR");
	
	/**
	 * <i>GRADUATING</i> Classification
	 */
	public static final Classification GRADUATING=new Classification("GRADUATING");
	
	/**
	 * <i>NEW_FRESHMAN</i> Classification
	 */
	public static final Classification NEW_FRESHMAN=new Classification("NEW FRESHMAN");
	
	/**
	 * <i>OLD_FRESHMAN</i> Classification
	 */
	public static final Classification OLD_FRESHMAN=new Classification("OLD FRESHMAN");
	
	/**
	 * Creates a classification with the given description.
	 * 
	 * @param classification
	 */
	public Classification(String classification){
		this.classification=classification;		
	}
	
	/**
	 * Returns the description of the classification.
	 * @return the description of the classification
	 */
	public String getDescription() {
		return classification;
	}
	
	/**
	 * Checks if the given <code>String</code> is a classification.
	 * 
	 * @param classification
	 * @return true if the given <code>String</code> is a classification
	 */
	public static boolean isClassification(String classification){
		if(classification.equals(FRESHMAN.getDescription())) return true;
		else if(classification.equals(SOPHOMORE.getDescription())) return true;
		else if(classification.equals(JUNIOR.getDescription())) return true;
		else if(classification.equals(SENIOR.getDescription())) return true;
		else if(classification.equals(GRADUATING.getDescription())) return true;
		else if(classification.equals(SUPER_SENIOR.getDescription())) return true;
		else return false;
	}
	
	/**
	 * Checks if the given classification has satisfied a specific prerequisite classification.
	 * 
	 * @param classification
	 * @param prereqClassification
	 * @return true if the given classification has satisfied a specific prerequisite classification
	 */
	public static boolean isSatisfied(String classification, String prereqClassification){
		if(prereqClassification.equals(GRADUATING.getDescription())){
			if(classification.equals(GRADUATING.getDescription()))
				return true;
			else
				return false;
		}
		if(prereqClassification.equals(SENIOR.getDescription())){
			if(classification.equals(SENIOR.getDescription()) || classification.equals(GRADUATING.getDescription()))
				return true;
			else
				return false;
		}
		if(prereqClassification.equals(JUNIOR.getDescription())){
			if(classification.equals(SENIOR.getDescription()) || classification.equals(JUNIOR.getDescription())) 
				return true;
			else
				return false;
		}
		if(prereqClassification.equals(SOPHOMORE.getDescription())){
			if(classification.equals(SENIOR.getDescription()) || classification.equals(JUNIOR.getDescription()) || classification.equals(SOPHOMORE.getDescription())) 
				return true;
			else 
				return false; 
		}
		if(prereqClassification.equals(FRESHMAN.getDescription()))
			return true;
		System.err.println("****[error] Classification prerequisite checking failed. ");
		return false;
	}
	
	/**
	 * Returns the classification associated with the given year level.
	 * 
	 * @param yearLevel
	 * @return the classification associated with given year level.
	 */
	public static Classification getClassificationValue(Integer yearLevel){
		switch(yearLevel){
			case 0:
				return NEW_FRESHMAN;
			case 1:
				return OLD_FRESHMAN;
			case 2:
				return SOPHOMORE;
			case 3:
				return JUNIOR;
			case 4:
				return SENIOR;
			default:
				if(yearLevel>4)
					return SUPER_SENIOR;
				else{
					System.err.println("****[warning] No classification value for yearLevel="+yearLevel+".");
					return null;
				}
		}
	}
}
